package design.create_factory;

import org.junit.Test;

/**
 * 工厂方法
 */
public class DemoFactoryMethod {
    @Test
    public void test() throws Exception {
        PhoneFactory factory=new XiaoMiPhoneFactory();
        Phone  phone=factory.makePhone();
        phone.welcome();
        factory = new HuaWeiMiPhoneFactory();
        phone = factory.makePhone();
        phone.welcome();
    }

    //抽象手机工厂
    public interface PhoneFactory {
         Phone makePhone()  throws Exception;
    }
    public class HuaWeiMiPhoneFactory implements PhoneFactory{
        @Override
        public Phone makePhone(){
            return new HuaWeiPhone();
        }
    }
    public class XiaoMiPhoneFactory implements PhoneFactory{
        @Override
        public Phone makePhone(){
            return new XiaoMiPhone();
        }
    }
}
